﻿Public Class Actualizar_Productos
    Inherits System.Web.UI.Page
    Dim c As New Conexion
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("VariableNombre") = Nothing Then
            Label1.Text = "Tienes que Logearte"
            btnLogout.Visible = False
        Else
            HyperLink1.Visible = False
            Label2.Text = "Bienvenido " + Session("VariableNombre").ToString()

            c.SeleccionarLetras(TextBox6, "select nombres from usuarios where login='" & Session("VariableNombre").ToString() & "'")
            Label2.Text = "Bienvenido " + TextBox6.Text


        End If
    End Sub

    Protected Sub btnLogout_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogout.Click
        Session("VariableNombre") = Nothing
        Response.Redirect("InicioSesion.aspx")
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim nombres2 As String = DropDownList1.SelectedItem.Text

        c.Seleccionar(TextBox7, "select idproducto from productos where descripcion='" & nombres2 & "'")
        ID = Convert.ToInt32(TextBox7.Text)

        Dim descripcion As String = TextBox1.Text
        Dim existencias As Integer = Convert.ToInt32(TextBox2.Text)
        Dim precio As String = TextBox3.Text

        Dim sentencia As String = "update productos set descripcion='" & descripcion & "', existencias=" & existencias & ", precio=" & precio & " where idproducto=" & ID

        c.Insertar_Actualizar_Eliminar(sentencia, "actualizados")
        Label1.Text = Conexion.msj_sql_server
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles DropDownList1.SelectedIndexChanged
        Try
            Dim descripcion2 As String = (DropDownList1.SelectedItem.Text())


            c.Seleccionar(TextBox7, "select idproducto from productos where descripcion='" & descripcion2 & "'")
            ID = Convert.ToInt32(TextBox7.Text)

            c.SeleccionarLetras(TextBox1, "select descripcion from productos where idproducto=" & ID & "")
            c.Seleccionar(TextBox2, "select existencias from productos where idproducto=" & ID & "")
            c.SeleccionarLetras(TextBox3, "select precio from productos where idproducto=" & ID & "")

        Catch ex As Exception
            MsgBox(ex.ToString)

        End Try
    End Sub
End Class